using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
#if LIVE
using Microsoft.Xna.Framework.GamerServices;
#endif
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Neat;
using Neat.Components;
using System.Diagnostics;
using Neat.GUI;

namespace Kinectoid
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class KinectoidGame : NeatGame
    {
        public KinectoidGame()
        {
            GameWidth = 1280;
            GameHeight = 720;
            GameBackgroundColor = Color.Black;
            FullScreen = false;
        }

        protected override void Initialize()
        {
            base.Initialize();
            HasConsole = true;
            ConsoleKey = Keys.OemTilde;
            Graphics.ApplyChanges();
            Window.Title = "Kinectoid";
            ShowMouse = true;
        }

        public override void FirstTime()
        {
            base.FirstTime();
            Console.Run("k_draw true");
        }
        
        protected override void Behave(GameTime gameTime)
        {
            if (IsTapped(Keys.F11)) Graphics.ToggleFullScreen();
            if (IsTapped(Keys.Pause)) IsPaused = !IsPaused;

            if (IsTapped(Keys.F1))
            {
                Console.Run("g_twoplayer false$_sh game");
            }
            if (IsTapped(Keys.F2))
            {
                Console.Run("g_twoplayer true$_sh game");
            }
            base.Behave(gameTime);
        }
        
        public override void AddScreens()
        {
            base.AddScreens();
            Screens["mainmenu"] = new IntroScreen(this);
            Screens["game"] = new KinectoidScreen(this);
            Screens["kinect"] = new CalibrateScreen(this);
        }
    }

    public class IntroScreen : Screen
    {
        public IntroScreen(NeatGame game) : base(game) { }

        public override void Initialize()
        {
            base.Initialize();

            Label l1;
            l1 = Form.NewControl("l1", new Label()).ToLabel();
            l1.Position = new Vector2(100);
            l1.Caption = "Welcome to Kinectoid!\n" +
                "Press [F1] to begin playing solo\n" +
                "or [F2] to begin a two player game.";

            Button b1;
            Form.NewControl("b1", b1 = new Button());
            b1.Size = new Vector2(150, 64);
            b1.Position = new Vector2(100, 200);
            b1.Caption = "Solo";
            b1.OnPressRun = "g_twoplayer false$_sh game";

            Button b2;
            Form.NewControl("b2", b2 = new Button());
            b2.Size = new Vector2(150, 64);
            b2.Position = new Vector2(300, 200);
            b2.Caption = "Two Player";
            b2.OnPressRun = "g_twoplayer true$_sh game";

            Button b3;
            Form.NewControl("b3", b3 = new Button());
            b3.Size = new Vector2(150, 64);
            b3.Position = new Vector2(500, 200);
            b3.Caption = "Calibrate";
            b3.OnPressRun = "sh kinect";
        }
    }
}
